perm filename PWITHR.SAI[BIG,HPM] blob
sn#390202 filedate 1978-10-25 generic text, type T, neo UTF8
PROCEDURE PWITHR(INTEGER ARRAY A; INTEGER N; REFERENCE BOOLEAN LAST);
comment collected algorithms #306;
begin
integer i,p,q,r;
label l12,l9,l4,l5,l2,l1,l3,l11,l6,l7,l8,l10,l99;
own integer m; own integer array b[1:100];
if ¬last then goto l12; last←false;
for i←1 step 1 until n do b[i]←a[i];
p←b[n];
for i←n step -1 until 1 do
if p≠b[i] then
begin m←i; go to l99 end;
m←0; go to l99;
l12: if m=0 then goto l10;
p←b[m]; q←m; r←0;
l9: i←n;
l4: if a[i]=p then goto l2;
if a[i]<p then r←i;
l5: i←i-1; goto l4;
l2: a[i]←b[n]-1; if r=0 then goto l8;
l1: a[r]←p; q←q+1;
l3: r←r+1; if r>n then goto l11 else if a[r]>p then goto l3;
l11: if b[q]=p then goto l1; r←0;
l6: r←r+1; if a[r]≥p then goto l6;
a[r]←b[q]; if q=n then goto l7;
q←q+1; goto l6;
l7: last←false; goto l99;
l8: q←q-1; if q=0 then goto l10;
if b[q]=p then goto l5;
p←b[q]; goto l9;
l10: last←true;
l99:
end;